package com.example.keli.ui.my.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.keli.R;
import com.example.keli.base.utils.DensityUtil;
import com.example.keli.base.utils.GlideUtil;
import com.example.keli.base.utils.ScreenUtil;
import com.example.keli.base.widget.RoundWhiteImageView;
import com.example.keli.ui.my.model.LoveReciveBean;
import com.example.keli.ui.my.model.VoteReceiveBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * description:
 * author: Allen
 * date: 2019/3/19 11:51
 */
public class VoteReceiveAdapter extends BaseQuickAdapter<VoteReceiveBean.DataBean, BaseViewHolder> {

    @BindView(R.id.iv_cover)
    ImageView ivCover;
    @BindView(R.id.tv_love_title)
    TextView tvLoveTitle;
    @BindView(R.id.tv_love_city)
    TextView tvLoveCity;
    @BindView(R.id.rl_love)
    RelativeLayout rlLove;
    @BindView(R.id.ll_image)
    LinearLayout llImage;
    @BindView(R.id.iv_avatar)
    RoundWhiteImageView ivAvatar;
    @BindView(R.id.tv_num)
    TextView tvNum;

    private Context mContext;

    public VoteReceiveAdapter(List<VoteReceiveBean.DataBean> mData, Context context) {
        super(R.layout.item_recive_love, mData);
        this.mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, VoteReceiveBean.DataBean mListBean) {
        helper.setText(R.id.tv_love_title, mListBean.getTitle());
        helper.setText(R.id.tv_love_city, "["+mListBean.getRegion_name()+"站]");
//        helper.setText(R.id.tv_tickets_num, String.valueOf(mListBean.getTicket_num()));
//        helper.setText(R.id.tv_num, String.valueOf(mListBean.getUserInfo().size()));
        helper.setText(R.id.tv_tickets_num, String.format(mListBean.getTicket_num()+"%s","票"));
        helper.setText(R.id.tv_num, String.format("查看全部  %s %s", mListBean.getUserInfo().size(), "人"));

        List<VoteReceiveBean.DataBean.UserInfoBean> datas = new ArrayList<>(mListBean.getUserInfo());
        LinearLayout layout = helper.getView(R.id.ll_image);
        layout.removeAllViews();
        for (int i=0; i<datas.size(); i++){
            if (i<3){
                ImageView imageView = new ImageView(mContext);
                imageView.setLayoutParams(new ViewGroup.LayoutParams(DensityUtil.dip2px(mContext, 30), DensityUtil.dip2px(mContext, 30)));
                GlideUtil.displayCircle(mContext, imageView, datas.get(i).getAvatar());
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT));
//                layoutParams.leftMargin = 15;
                layoutParams.rightMargin = 5;
                layoutParams.bottomMargin = 10;
                layout.addView(imageView, layoutParams);
            }
        }

        ImageView cover = helper.getView(R.id.iv_cover);
        GlideUtil.displayRound(cover.getContext(), cover, mListBean.getCover_picture(), 5);
    }

}
